<template>
  <div class="dialog-wrapper" v-if="showLinkList">
    <div class="dialog-block">
      <i class="el-icon-circle-close-outline icon-del"
         @click="changeShow"
      ></i>
      <div class="dialog">
        <p class="title">从素材库选择链接</p>
        <div class="clearfix chousetype">
              <div class="btngroup">
              <el-input
                placeholder="请输入内容"
                suffix-icon="el-icon-search"
                v-model="searchContent">
              </el-input>
            </div>
        </div>
       
      
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[3, 6, 9, 12]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        class="pagelist"
        :total="total">
      </el-pagination>
      <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      border
      style="width: 100%"
      class="linktable"
      size="mini"
      center
      @selection-change="handleSelectionChange">
      <el-table-column
        type="selection"
        label="全选"
        width="55">
      </el-table-column>
      <el-table-column
        type="index"
        label="序号"
        width="60">
      </el-table-column>
      <el-table-column
        label="链接名称"
        prop="name"
        width="200">

      </el-table-column>
      <el-table-column
        prop="url"
        label="链接地址"
        width="300">
      </el-table-column>
      <el-table-column
        label="最近修改时间"
        >
        <template slot-scope="scope">{{ scope.row.createTime | formatDate }}</template>
      </el-table-column>
      <el-table-column
        label="操作"
        width="220"
        align="center"
        class-name="operation"
        >
        <template slot-scope="scope">
          <el-button
            @click.native.prevent="editRow(scope.$index, tableData)"
            type="text"
            size="small" class="tabbtn">
            编辑
          </el-button>
          <el-button
           @click.native.prevent="deleteRow(scope.$index, tableData)"
            type="text"
            size="small" class="tabbtn">
            删除
          </el-button>
        </template>

      </el-table-column>
    </el-table>
        <el-button type="primary" class="btnConfirm" @click="btnConfirm(multipleSelection)">确定</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {formatDate} from "@/utils/dateFomart";
import { getLinkTable } from "@/api/matter";
export default {
  name: "picDialog",
  props: {
    showLinkList: {
      type: Boolean,
      default: false
    },
    dialoglistList: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      formInline: {
        user: "",
        region: ""
      },
      tableData: [],
      multipleSelection: [],
      currentPage: 1,
      pageSize:5,
      total:0,
      searchContent:"",
      form: {
        name: "",
        address: "",
        methods: "全部",
        map: "地图链接"
      },
      formLabelWidth: "120px"
    };
  },
   filters: {
        formatDate(time) {
            var date = new Date(time);
            return formatDate(date, 'yyyy-MM-dd hh:mm');
        }
    },
  mounted() {
    this.getTable(this.pageSize,this.currentPage);
    // updated ();
  },
  methods: {
    changeShow() {
      
      this.$emit("hidden-linklist",false);
    },
    handleSelectionChange(val) {
      console.log(val);
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      this.pageSize=val;
      this.getTable(this.pageSize,this.currentPage);
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.currentPage=val;
      this.getTable(this.pageSize,this.currentPage);
      console.log(`当前页: ${val}`);
    },
    btnConfirm(val){
      let data={
        isShow:false,
        val:val
      }
       this.$emit("hidden-linklist",data)
    },
    getTable(pageSize,pagecur){
      let pagelist={
        pageNum: pagecur,
        pageSize: pageSize
      }
      getLinkTable(pagelist).then(res=>{
        console.log(res.data);
       
        this.tableData=res.data.data;
        this.total=res.data.elementsSum;
      }).catch(error=>{
        console.log(error)
      })
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.dialog-wrapper {
  position: absolute;
  top: -44px;
  left: -46px;
  width: calc(100% + 88px);
  height: calc(100% + 44px);
  text-align: center;
  z-index: 2;
  background-color: rgba(0, 0, 0, 0.5);
  .dialog-block {
    margin-left: 82px;
    .icon-del {
      margin-top: 182px;
      font-size: 34px;
      padding: 30px;
      cursor: pointer;
      color: #fff;
      &::after {
        display: block;
        width: 1px;
        height: 52px;
        margin-left: 50%;
        margin-bottom: -34px;
        background-color: #fff;
        content: "";
      }
    }
    .dialog {
      position: relative;
      width: 82%;
      height: 600px;
      margin-left: 130px;
      border-radius: 10px;
      background-color: #fff;
      .chousetype {
        padding: 8px;
        .selectmethod {
          float: left;
          .el-form-item {
            margin-bottom: 0;
          }
        }
      }
      .el-pagination {
        text-align: left;
        margin: 8px;
        padding-left: 20px;
      }
      .btnConfirm{
        margin: 8px;
      }
      .title {
        margin: 0;
        text-align: left;
        line-height: 20px;
        font-size: 20px;
        font-weight: 700;
        &::before {
          display: inline-block;
          margin: 12px 10px 0 12px;
          vertical-align: bottom;
          width: 8px;
          height: 20px;
          background-color: #2ce2e0;
          content: "";
        }
      }
      .inp-wrapper {
        margin-top: 48px;
        text-align: left;
        .inp-name {
          margin: 0 9px 0 29px;
          font-size: 18px;
        }
      }
    }
  }
}
</style>
